package com.cskaoyan.wordmemorize.controller.app;

import com.cskaoyan.wordmemorize.auth.StpKit;
import com.cskaoyan.wordmemorize.common.result.Result;
import com.cskaoyan.wordmemorize.common.util.IpUtil;
import com.cskaoyan.wordmemorize.dto.admin.PageDTO;
import com.cskaoyan.wordmemorize.dto.app.AppLoginDTO;
import com.cskaoyan.wordmemorize.dto.app.UserCheckinDTO;
import com.cskaoyan.wordmemorize.dto.app.UserCheckinStatisticsDTO;
import com.cskaoyan.wordmemorize.request.PageRequest;
import com.cskaoyan.wordmemorize.request.PhoneNumberLoginCommand;
import com.cskaoyan.wordmemorize.service.LoginService;
import com.cskaoyan.wordmemorize.service.UserCheckinService;
import jakarta.annotation.Resource;
import jakarta.servlet.http.HttpServletRequest;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("user")
public class AppLoginController {

    @Resource
    LoginService loginService;
    @Resource
    UserCheckinService userCheckinService;


    // APP端手机号登录
    @PostMapping("login/phone")
    public Result<AppLoginDTO> phoneLogin(@RequestBody PhoneNumberLoginCommand command, HttpServletRequest request) {
        // 检查校验码是否正确

        String ipAddr = IpUtil.getIpAddr(request);
        AppLoginDTO appLoginDTO = loginService.phoneNumberLogin(command, ipAddr);
        return Result.ok(appLoginDTO);
    }

    // APP端登出
    @PostMapping("logout")
    public Result logout() {
        StpKit.USER.logout();
        return Result.ok();
    }

}
